/*
 */
package edu.wpi.first.wpilibj.util;

/**
 *
 * @author Dylan Frese
 */
public class Rectangle3D implements Cloneable{
    
    Point3D where;
    Dimension3D size;

    public Rectangle3D(Point3D p, Dimension3D d) {
        where = p;
        size = d;
    }

    public Rectangle3D(double x, double y, double z, double width, double depth, double height) {
        this (new Point3D(x, y, z), new Dimension3D(width, depth, height));
    }

    public double getHeight() {
        return size.height;
    }

    public double getWidth() {
        return size.width;
    }

    public double getX() {
        return where.x;
    }

    public double getY() {
        return where.y;
    }

    public boolean isEmpty() {
        return size.depth <= 0 || size.width <= 0 || size.height <= 0;
    }

    public void setFrame(double x, double y, double z, double w, double h, double d) {
        where.x = x;
        where.y = y;
        where.z = z;
        size.width = w;
        size.height = h;
        size.depth = d;
    }

    public boolean contains(double x, double y, double z) {
        return  x >= where.x && x <= where.x + size.width &&
                y >= where.y && y <= where.y + size.depth &&
                z >= where.z && z <= where.z + size.height;
    }

    public boolean contains(double x, double y, double z, double w, double d, double h) {
        return contains (x, y, z) && contains (x + w, y + d, z + h);
    }

    public boolean contains(Point3D p){
        return contains (p.x, p.y, p.z);
    }
    
    public boolean intersects(double x, double y, double z, double w, double d, double h) {
        //May be optimized. Pretty noobish way of doing things, and, probably slow.
        boolean b = true;
        Line2D lx = new Line2D(x, 0, x + w, 0);
        Line2D ly = new Line2D(y, 0, y + d, 0);
        Line2D lz = new Line2D(z, 0, z + h, 0);
        b = b && lx.intersects(where.x, 0, size.width, 0);
        b = b && ly.intersects(where.y, 0, size.depth, 0);
        b = b && lz.intersects(where.z, 0, size.height, 0);
        return b;
    }
    
    public boolean intersects(Rectangle3D r){
        return intersects (r.where.x, r.where.y, r.where.z, r.size.width, r.size.depth, r.size.height);
    }
    
    @Override
    public Rectangle3D clone(){
        return new Rectangle3D(where.x, where.y, where.z, size.width, size.depth, size.height);
    }
    
}
